package com.tang.script.command;

import com.tang.script.extrator.ConstantsExtractor;
import com.tang.script.extrator.FunctionsExtractor;
import com.tang.script.extrator.VariablesExtractor;
import com.tang.script.functions.FunctionsLinker;
import com.tang.script.variable.VariablesContainer;
import lombok.Builder;

public class CacheScriptCommand extends AbstractScriptCommand<Void> {

    @Builder
    public CacheScriptCommand(String scriptText, VariablesContainer variablesContainer) {
        super(scriptText, variablesContainer);
    }

    @Override
    public Void execute() {
        initCommand();
        ConstantsExtractor constantsExtractor = ConstantsExtractor.get();
        constantsExtractor.extracte(this);

        VariablesExtractor variablesExtractor = VariablesExtractor.get();
        variablesExtractor.extracte(this);

        FunctionsExtractor functionsExtractor = FunctionsExtractor.get();
        functionsExtractor.extracte(this);

        FunctionsLinker functionsLinker = FunctionsLinker.get();
        functionsLinker.linkFunctions(this);

        return doExecute();
    }

    @Override
    public Void doExecute() {
        setScript(getGroovyShell());
        return null;
    }

    @Override
    public Class getResultClass() {
        return Void.class;
    }
}
